<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/waywardyux/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/waywardyux/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/waywardyux/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/waywardyux/images/logo.svg" color="#222">

<link rel="stylesheet" href="/waywardyux/css/main.css">


<link rel="stylesheet" href="/waywardyux/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"waywardyux.gitee.io","root":"/waywardyux/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="掌控自己的代码 记一次有收获的面试过程，这可能会改变我迄今为止的代码习惯和认知，并且我会受益于其中休要花里胡哨!!!">
<meta property="og:type" content="article">
<meta property="og:title" content="掌控自己的代码">
<meta property="og:url" content="https://waywardyux.gitee.io/2021/03/20/%E6%8E%8C%E6%8E%A7%E8%87%AA%E5%B7%B1%E7%9A%84%E4%BB%A3%E7%A0%81/index.html">
<meta property="og:site_name" content="赶路贝壳">
<meta property="og:description" content="掌控自己的代码 记一次有收获的面试过程，这可能会改变我迄今为止的代码习惯和认知，并且我会受益于其中休要花里胡哨!!!">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-03-20T12:51:30.000Z">
<meta property="article:modified_time" content="2021-12-23T05:37:14.645Z">
<meta property="article:author" content="yux">
<meta property="article:tag" content="随笔">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://waywardyux.gitee.io/2021/03/20/%E6%8E%8C%E6%8E%A7%E8%87%AA%E5%B7%B1%E7%9A%84%E4%BB%A3%E7%A0%81/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>掌控自己的代码 | 赶路贝壳</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/waywardyux/atom.xml" title="赶路贝壳" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/waywardyux/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">赶路贝壳</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">想点好活儿整整</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/waywardyux/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/waywardyux/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/waywardyux/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">3</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/waywardyux/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">4</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/waywardyux/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">4</span></a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://waywardyux.gitee.io/2021/03/20/%E6%8E%8C%E6%8E%A7%E8%87%AA%E5%B7%B1%E7%9A%84%E4%BB%A3%E7%A0%81/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/waywardyux/images/head.jpg">
      <meta itemprop="name" content="yux">
      <meta itemprop="description" content="虚假快乐小牛马">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="赶路贝壳">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          掌控自己的代码
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-20 20:51:30" itemprop="dateCreated datePublished" datetime="2021-03-20T20:51:30+08:00">2021-03-20</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-12-23 13:37:14" itemprop="dateModified" datetime="2021-12-23T13:37:14+08:00">2021-12-23</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/waywardyux/categories/%E6%9C%AA%E5%88%86%E7%B1%BB/" itemprop="url" rel="index"><span itemprop="name">未分类</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="掌控自己的代码"><a href="#掌控自己的代码" class="headerlink" title="掌控自己的代码"></a>掌控自己的代码</h1><blockquote>
<p>记一次有收获的面试过程，这可能会改变我迄今为止的代码习惯和认知，并且我会受益于其中<br>休要花里胡哨!!!</p>
</blockquote>
<span id="more"></span>


<p>面试官让我写了一段代码，大致是两个数组之间的相互加减操作</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">float</span> max = <span class="built_in">fmax</span>(arr);</span><br><span class="line"><span class="keyword">float</span> min = <span class="built_in">fmin</span>(arr);</span><br><span class="line"></span><br><span class="line"><span class="keyword">float</span> k = max-min;</span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">char</span> *ptr = res;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">float</span> *i = arr; i &lt; arr + n; i++)&#123;</span><br><span class="line">    *ptr++ = (*i - min)/k * <span class="number">255</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>面试官:你觉得你的代码有什么问题吗？<br>我: 可能就是在k可能带来的除0问题把<br>面试官:其它的呢？<br>我: …</p>
<p>面试官: 你写代码一定要肯定自己的输入输出，程序计算出的结构你要肯定，而不是让其他因素来影响你<br>我: …</p>
<p> <em>你的i是float，prt是uchar，你知道会怎样做类型转换吗</em></p>
<p> 编译器会自动去做</p>
<p> <em>一定会这样去做吗，或者有不同的处理办法，不同的编译器呢？不要让编译器去决定你程序的运行结果，要对自己代码的结果要有一个肯定</em></p>
<p>我明白了，我可以在计算是加上类型转换的关键字</p>
<hr>
<p>在我的认知中，代码高手就是各种技巧乱飞，能隐式绝不显示，arr[i]要写成 *(arr + i)，注意布局的美感，一通花里胡哨。而往往忽略了程序的关键问题，正确性和肯定性和易读性</p>
<p>这是一个小小的问题，但却启发了我。<br>未来，做一个确信自己代码的人</p>
<p>改变ing</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/waywardyux/tags/%E9%9A%8F%E7%AC%94/" rel="tag"># 随笔</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/waywardyux/2021/03/20/blog-%E8%AE%A1%E5%88%92%E7%AC%AC%E4%B8%80%E6%AD%A5-hexo-github-page-%E6%90%AD%E5%BB%BA/" rel="prev" title="blog 计划第一步: hexo + github page 搭建">
      <i class="fa fa-chevron-left"></i> blog 计划第一步: hexo + github page 搭建
    </a></div>
      <div class="post-nav-item">
    <a href="/waywardyux/2021/12/23/sorry1223/" rel="next" title="1223想起来了博客">
      1223想起来了博客 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%8E%8C%E6%8E%A7%E8%87%AA%E5%B7%B1%E7%9A%84%E4%BB%A3%E7%A0%81"><span class="nav-number">1.</span> <span class="nav-text">掌控自己的代码</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="yux"
      src="/waywardyux/images/head.jpg">
  <p class="site-author-name" itemprop="name">yux</p>
  <div class="site-description" itemprop="description">虚假快乐小牛马</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/waywardyux/archives/">
        
          <span class="site-state-item-count">4</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/waywardyux/categories/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/waywardyux/tags/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/iyux" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;iyux" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:yux.scse@gmail.com" title="E-Mail → mailto:yux.scse@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yux</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/waywardyux/lib/anime.min.js"></script>
  <script src="/waywardyux/lib/velocity/velocity.min.js"></script>
  <script src="/waywardyux/lib/velocity/velocity.ui.min.js"></script>

<script src="/waywardyux/js/utils.js"></script>

<script src="/waywardyux/js/motion.js"></script>


<script src="/waywardyux/js/schemes/pisces.js"></script>


<script src="/waywardyux/js/next-boot.js"></script>




  















  

  

</body>
</html>
